package com.example.g7640.controller;


import com.example.g7640.builder.ResultBuilder;
import com.example.g7640.dto.ProductDto;
import com.example.g7640.dto.ProductQuery;
import com.example.g7640.dto.common.PageResult;
import com.example.g7640.dto.common.Result;
import com.example.g7640.entity.Product;
import com.example.g7640.service.ProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author  
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/api/product")
public class ProductController {
    @Resource
    ProductService productService;


    @GetMapping("/get-list")
    public PageResult<List<ProductDto>> query(ProductQuery query){
        return productService.query(query);
    }


    @GetMapping("/get-info")
    public Result<ProductDto> getInfo(Integer id){
        return ResultBuilder.buildSuccess(productService.getInfo(id));
    }


    @PostMapping("/add")
    public Result<String> add(@RequestBody ProductDto productDto){
        productService.add(productDto);
        return ResultBuilder.buildSuccess();
    }

    @PostMapping("/update-args")
    public Result<String> update(@RequestBody ProductDto productDto){
        productService.update(productDto);
        return ResultBuilder.buildSuccess();
    }

    @PostMapping("/update-status")
    public Result<String> updateStatus(@RequestBody ProductDto productDto){
        productService.updateStatus(productDto);
        return ResultBuilder.buildSuccess();
    }


    @GetMapping("/del")
    public Result<String> delete(Integer id){
        productService.delete(id);
        return ResultBuilder.buildSuccess();
    }


}
